package com.xsj.controller;

import com.xsj.dto.ResponseDto;
import com.xsj.service.GoodsService;
import java.util.HashMap;
import java.util.List;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "GoodsController")
@CrossOrigin
@RestController
@RequestMapping({"/goods"})
public class GoodsController {
    @Autowired
    private GoodsService goodsService;



    @Operation(summary = "商品", description = "根据店铺id获取商品信息")
    @GetMapping({"/list"})
    public ResponseDto goodsList(@RequestParam("merchantId") Integer merchantId) {
        List<HashMap<String, Object>> goodsByMerchantId = goodsService.getGoodsByMerchantId(merchantId);
        return ResponseDto.success(goodsByMerchantId);
    }

    @Operation(summary = "商品规格", description = "根据商品id获取商品规格")
    @GetMapping({"/spec"})
    public ResponseDto goodsSpec(@RequestParam("goodId") Integer goodId) {
        List<HashMap<String, Object>> goodsSpec = goodsService.getGoodsSpec(goodId);
        return ResponseDto.success(goodsSpec);
    }

    @Operation(summary = "商品类型", description = "根据商品id获取商品类型")
    @GetMapping({"/type"})
    public ResponseDto goodsType(@RequestParam("typeId") Integer typeId) {
        List<HashMap<String, Object>> goodsType = goodsService.getGoodsType(typeId);
            return ResponseDto.success(goodsType);
    }

    @Operation(summary = "店铺商品类型列表", description = "根据店铺id获取商品类型")
    @GetMapping({"/categories"})
    public ResponseDto goodsCategories(@RequestParam("merchantId") Integer merchantId) {
            List<HashMap<String, Object>> goodsList = goodsService.getGoodsList(merchantId);
            return ResponseDto.success(goodsList);
    }


}
